package com.iplatform.file.function.resourcedata.action;


import com.iplatform.commons.utils.CommResponse;
import com.iplatform.file.function.resourcedata.entity.BasicDataBean;
import com.iplatform.file.function.resourcedata.service.impl.BasicDataServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "基础数据操作模块接口")
@RestController
@RequestMapping("/basicData")
public class BasicDataController {
    @Resource
    private BasicDataServiceImpl basicDataService;

    @PostMapping(value = "/addBasicData")
    @ApiOperation(value = "添加操作", notes = "所在包：com.iplatform.data.function.resource.controller 方法名：addBasicData")
    @ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
            @ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
    public ResponseEntity<CommResponse<Integer>> addBasicData(BasicDataBean basicDataBean){

        Integer result =  basicDataService.insert(basicDataBean);
        return new ResponseEntity<>(new CommResponse<Integer>(HttpStatus.CREATED.toString(), Boolean.TRUE,result), HttpStatus.CREATED);
    }


    @DeleteMapping("/deleteById")
    @ApiOperation(value = "逻辑删除操作", notes = "所在包：com.iplatform.data.function.resource.controller 方法名：deleteById")
    @ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
            @ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
    public ResponseEntity<CommResponse<Integer>> deleteById(Long id){
        Integer result = basicDataService.deleteBasicDataById(id);
        return new ResponseEntity<>(new CommResponse<Integer>(HttpStatus.NO_CONTENT.toString(), Boolean.TRUE,result), HttpStatus.NO_CONTENT);
    }


    @PutMapping("/updateBasicData")
    @ApiOperation(value = "修改操作操作", notes = "所在包：com.iplatform.data.function.resource.controller 方法名：updateBasicData")
    @ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
            @ApiResponse(code = HttpServletResponse.SC_BAD_REQUEST, message = "参数错误"),
            @ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
    public ResponseEntity<CommResponse<Integer>> updateBasicData( BasicDataBean basicDataBean){

        Integer result = basicDataService.updateBasicData(basicDataBean);
        return new ResponseEntity<>(new CommResponse<Integer>(HttpStatus.NO_CONTENT.toString(), Boolean.TRUE,result), HttpStatus.NO_CONTENT);

    }


    @GetMapping("/getDataById")
    @ApiOperation(value = "根据ID号查询操作", notes = "所在包：com.iplatform.data.function.resource.controller 方法名：getDataById")
    @ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
            @ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
    public ResponseEntity<CommResponse<BasicDataBean>> getDataById(@RequestParam  Long parentId){
        BasicDataBean result = basicDataService.getBasicDataById(parentId);
        CommResponse<BasicDataBean> response = new CommResponse<>();
        response.setMsg(HttpStatus.OK.toString());
        response.setRes(Boolean.TRUE);
        response.setResult(result);
        return new ResponseEntity<>(response,HttpStatus.OK);

    }


}
